package web.converter;

import org.apache.log4j.Logger;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;

import java.text.SimpleDateFormat;
import java.util.Date;

public class BaseController {
    private Logger logger = Logger.getLogger(BaseController.class);

    /**
     * 使用@InitBinder解决SpringMVC日期类型无法绑定的问题
     * @param dataBinder
     */
    @InitBinder
    public void initBinder(WebDataBinder dataBinder){
        logger.info("进入BaseController的initBinder方法");
        dataBinder.registerCustomEditor(
                Date.class,
                new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true)
        );
    }
}
